package com.web.kdl.controller.maDataReport;

import com.web.kdl.common.result.CommonResult;
import com.web.kdl.entity.historyEvent.HistoryEvent;
import com.web.kdl.pojo.form.DataReportForm;
import com.web.kdl.pojo.form.HistoryEventForm;
import com.web.kdl.service.HistoryEvent.HistoryEventService;
import com.web.kdl.service.excel.ExcelService;
import com.web.kdl.service.maDataReport.DataReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
public class HistoryEventController {
    
    @Autowired
    private HistoryEventService historyEventService;
    @Autowired
    private ExcelService excelService;

    //获取一个时间节点的所有飞轮的数据信息
    @PostMapping("/getAllHistoryEvent")
    @ResponseBody
    public CommonResult<List<HistoryEvent>> getAllHistoryEvent(){
        List<HistoryEvent> allHistoryEvent = historyEventService.getAllHistoryEvent();
        return CommonResult.success(allHistoryEvent);
    }

    //获取查询的一个设备的数据信息 内置导出excel文件方法
    @PostMapping("/getHistoryEvent")
    @ResponseBody
    public CommonResult<List<Map<String, Object>>>  getHistoryEvent(@RequestBody HistoryEventForm HistoryEventForm){
        List<Map<String, Object>> HistoryEvent = historyEventService.getHistoryEvent(HistoryEventForm);
       return CommonResult.success(HistoryEvent);
    }

    /**
     * 提交导出任务（异步）
     */
    @PostMapping("/submitHisExportTask")
    @ResponseBody
    public CommonResult submitExportTask(@RequestBody DataReportForm dataReportForm){
        return historyEventService.submitExportTask(dataReportForm);
    }

    /**
     * 查询导出任务状态
     */
    @PostMapping("/queryHisExportTask")
    @ResponseBody
    public CommonResult queryExportTask(@RequestBody Map<String, String> params){
        String taskId = params.get("taskId");
        return excelService.queryExportTask(taskId);
    }
}
